#include <vector>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

int solution(vector<int> counters){
    //求出汇总值
    int s = accumulate(counters.begin(), counters.end(), 0);
    vector<int> factor;

    //特殊情况，counters里都是0
    if(s == 0){
        return 0;
    }

    //根据数组大小，求出汇总值的因数，放入数组
    for(int r = counters.size(); r > 0; --r){
        if(s % r == 0){
            factor.push_back(s / r);
        }
    }

    for(int i = 0; i < factor.size(); ++i){
        int num = factor[i];
        int tmp = 0;
        int step = 0;
        for(int j = 0; j < counters.size(); ++j){
            tmp += counters[j];
            if(tmp > num){
                break;
            }
            else if(tmp == num){
                tmp = 0;
            }
            else{
                continue;
            }
        }
        if(tmp == 0){
            step = counters.size() - s / factor[i];
            return step;
        }
    }

    return -1;
}

int main(int argc, char const *argv[])
{
    ifstream ifs("sleepinginclass.in");
    ofstream ofs("sleepinginclass.out");
    int num = 0;
    int nums = 0;
 
    ifs >> num;
    for(int i = 0; i < num; ++i){
        vector<int> counters;
        ifs >> nums;
        for(int j = 0; j < nums; ++j){
            int tmp = 0;
            ifs >> tmp;
            counters.push_back(tmp);
        }
        ofs << solution(counters) << endl;       
    }

    return 0;
}
